package com.fjec.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjec.user.entity.SysPermission;
import com.fjec.user.mapper.SysPermissionMapper;
import com.fjec.user.service.ISysPermissionService;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 005.权限表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2020-08-31
 */
@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {

    @Resource
    private SysPermissionMapper mapper;

    @Override
    @Cacheable(value = "permissionCache", key = "#roleCode")
    public List<String> getPermsByRoleCode(String roleCode) {
        return doGetPermsByRoleCode(roleCode);
    }

    @Override
    @CachePut(value = "permissionCache", key = "#roleCode")
    public List<String> cachePermsByRoleCode(String roleCode) {
        return doGetPermsByRoleCode(roleCode);
    }

    private List<String> doGetPermsByRoleCode(String roleCode) {
        return mapper.getPermsByRoleCode(roleCode);
    }
}
